package com.csun.cmny.provider.model.domain;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-02-13 16:42
 * @Description: the class device bind base entity
 */
@Data
public class DeviceBindBaseEntity implements Serializable {

    private static final long serialVersionUID = 1393168568666085158L;

    /**
     * PERSONAL - 个人, ENTERPRISE - 企业
     */
    @Column(name = "bind_way")
    private String bindWay;

    /**
     * 创建人
     */
    private String creator;

    /**
     * 创建人ID
     */
    @Column(name = "creator_id")
    private Long creatorId;

    /**
     * 创建时间
     */
    @Column(name = "created_time")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdTime;

    @Transient
    private Integer pageNum;

    @Transient
    private Integer pageSize;

    @Transient
    private String orderBy;

    /**
     * Sets update info.
     *
     * @param user the user
     */
    @Transient
    @JsonIgnore
    public void setUpdateInfo(LoginAuthDto user) {

        this.creatorId = user.getUserId();
        this.creator = user.getUserName();
        this.createdTime = new Date();
    }

}
